package net.zhuike.novel.app.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.LinearLayout;

import com.luomi.lm.ad.ADType;
import com.luomi.lm.ad.DRAgent;
import com.luomi.lm.ad.IAdSuccessBack;
import com.umeng.analytics.MobclickAgent;

import net.zhuike.novel.app.R;

import framework.common.baseui.UeBaseActivity;

/**
 * Created by qi.wang on 2017/7/26.
 */

public class AdsActivity extends UeBaseActivity{
    LinearLayout ll_layout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        baseSetContentView(R.layout.activity_ad);
        hiddenFooter();
        hiddenHeader();
        ll_layout=(LinearLayout) findViewById(R.id.ll_layout);
        /** * this  上下文
                * adtype 广告类型（详情请看附录表）
		 * true  针对开屏是否显示倒计时展示 针对banner是是否显示关闭按钮
		 * IAdSuccessBack 广告展示回调接口
		 */
        DRAgent.getInstance().getOpenView(getApplicationContext(), ADType.FULL_SCREEN,  true, new IAdSuccessBack() {

            @Override
            public void onError(final String result) {

                // TODO Auto-generated method stub
                System.out.println(">>>>>>广告展示失败:" + result);
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        goHome();
                    }
                });


                // TODO Auto-generated method stub

            }

            @Override
            public void onClick(String result) {
                // TODO Auto-generated method stub
                // TODO Auto-generated method stub
                System.out.println(">>>>>广告被点击:" + result);
            }

            @Override
            public void OnSuccess(String result) {
                // TODO Auto-generated method stub

                // TODO Auto-generated method stub
                System.out.println(">>>广告展示成功:" + result);
                if (result.equals("7")) {
                    goHome();
                }

            }

            @Override
            public void OnLoadAd(View view) {
                // TODO Auto-generated method stub
                ll_layout.addView(view);
            }
        });
    }
    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("广告");
        MobclickAgent.onResume(context);
    }
    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("广告");
        MobclickAgent.onPause(context);
    }
    private synchronized void goHome() {


            finish();

    }
    Handler handler=new Handler(){
        public void handleMessage(android.os.Message msg) {

        };
    };
}
